package com.yc.spring.jdbc;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class BankBiz {

    @Resource
    AccountDao adao;
    @Resource
    RecordDao rdao;

    @Transactional(rollbackFor = BizException.class)
    public void deposit( int id, double money) throws BizException {
        // TODO 省略业务判断
        adao.update(id, money);
        // int i = 1/0; 运行时异常
        boolean bool = true;
        if(bool){
            // 默认情况下, Spring 只会回滚运行时异常
            throw new BizException("编译期异常!");
        }

        rdao.insert(id, money);
    }

    @Resource
    B b;
    @Transactional
    public void a(){
        System.out.println("--------- a ------");
        b.b();
    }

    @Transactional(propagation = Propagation.NEVER)
    public void b(){
        System.out.println("--------- b ------");
    }


}

